package org.jaaksi.kottlindemo.util

import android.content.Context
import android.text.format.DateFormat
import android.text.format.DateUtils
import org.jaaksi.kottlindemo.R
import java.text.SimpleDateFormat
import java.util.*

object DateUtil {
    fun getTimeString(context: Context, j: Long): String? {

        val str = if (DateFormat.is24HourFormat(context)) "H:mm" else "h:mm a"
        val locale = Locale.getDefault()
        return SimpleDateFormat(
            DateFormat.getBestDateTimePattern(
                locale,
                "EEE, MM/dd, $str"
            ), Locale.getDefault()
        ).format(Date(j))
    }


    fun test(context: Context, timestamp: Long) {
        val locale = Locale.getDefault()
        // 是否是今天
        DateUtils.isToday(timestamp)

        // 是否是24小时制
        DateFormat.is24HourFormat(context)

        // "MMM" Local.getDefault() 如果是英文，月份会格式为英文
        SimpleDateFormat("MMM dd", locale)

        // getBestDateTimePattern
        DateFormat.getBestDateTimePattern(locale, "EEE, MM/dd")
    }
}